package com.study.app.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.study.app.domain.AppUserCoupon;
import com.study.app.domain.bo.AppUserCouponBo;
import com.study.app.domain.vo.AppUserCouponVo;
import com.study.app.mapper.AppUserCouponMapper;
import com.study.app.service.IAppUserCouponService;
import com.study.common.exception.ServiceException;
import com.study.common.utils.StringUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * 用户问题反馈Service业务层处理
 *
 * @author study
 * @date 2023-04-20
 */
@RequiredArgsConstructor
@Service
public class AppUserCouponServiceImpl implements IAppUserCouponService {

    private final AppUserCouponMapper baseMapper;


    @Override
    public List<AppUserCouponVo> getUserCoupon(AppUserCouponBo userCouponBo) {

        if (StringUtils.isBlank(userCouponBo.getUserCode())) {
            throw new ServiceException("用户code不能为空");
        }

        LambdaQueryWrapper<AppUserCoupon> wr = new LambdaQueryWrapper<>();
        wr.eq(AppUserCoupon::getUserCode, userCouponBo.getUserCode())
                .eq(AppUserCoupon::getIsUser, 1)
                .eq(AppUserCoupon::getIsOverdue, 1)
                .gt(AppUserCoupon::getEndTime, new Date());
        return baseMapper.selectVoList(wr);

    }
}
